package edu.gatech.cs2340.teamrocket.model.map;

import java.io.Serializable;
import edu.gatech.cs2340.teamrocket.model.storage.*;

/**
 * This is the abstract class to represent locations.
 *
 * @author Joe Tacheron
 */
public abstract class Location implements Serializable {

    protected String name;
    protected int endDist;
    protected ShopInventory shop;

    /**
     *
     * @param name The name of the Location
     * @param endDist The distance at which the Location ends
     */
    Location(String name, ShopInventory si, int endDist){
        this.name = name;
        this.endDist = endDist;
        shop = si;
    }

    Location(String name, int endDist){
        this(name, (ShopInventory)null, endDist);
    }

    /**
     * @return true if the location has a shop, false otherwise.
     */
    public boolean hasShop(){
        return shop != null;
    }

    /**
     * @return The shop associated with this Location or null if there is no shop.
     */
    public ShopInventory getShop(){
        if(shop == null)
            throw new NullPointerException("There is no shop at this Location");
        return shop;
    }

    /**
     * @return The distance from the beginning location(distance 0) where this location ends.
     */
    public int getEndDist() {
        return endDist;
    }

    public String getName() {
        return name;
    }

    /**
     * @return the type of the location (plains, town, etc.) as a String
     */
    public String getType() {
        String classname = this.getClass().getName();
        int startingIndex = classname.lastIndexOf ('.') + 1;
        String typename = classname.substring(startingIndex);
        return typename;
    }

    /**
     * @return the name and type, in parenthesis.
     */
    @Override
    public String toString(){
        return getName() + " (" + getType() + ")";
    }
}